package behavior.chain_of_responsibility;

public abstract class LogManager {
	public static final int ERROR = 3;
	public static final int INFO  = 2;
	public static final int DEBUG = 1;
	protected int level;
	protected LogManager nextLog;
	protected LogManager(int level){
		this.level = level;
	}
	public void setNextLogManager(LogManager logManager){
		this.nextLog = logManager;
	}
	public void logManager(int level, String message){
		if(this.level <= level){
			writeLog(message);
		}
		if(nextLog != null){
			nextLog.logManager(level, message);   //类似于递归调用
		}
	}
	public abstract void writeLog(String message);
}

class Error extends LogManager {
	protected Error(int level) {
		super(level);
	}
	@Override
	public void writeLog(String message) {
		System.out.println("ERROR:"+message);
	}
}
class Info extends LogManager {
	protected Info(int level) {
		super(level);
	}
	@Override
	public void writeLog(String message) {
		System.out.println("INFO:"+message);
	}
}
class Debug extends LogManager {
	protected Debug(int level) {
		super(level);
	}
	@Override
	public void writeLog(String message) {
		System.out.println("DEBUG:"+message);
	}
}


